package com.meng.mmlive;

import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.meng.baselibrary.activity.BaseActivity;
import com.meng.mmlive.ui.activity.MainActivity;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.rong.imlib.RongIMClient;

/**
 * Created by Administrator on 2017/5/15.
 */

public class LoginActivity extends BaseActivity {
    @Bind(R.id.btn1)
    Button btn1;
    @Bind(R.id.btn2)
    Button btn2;
    String token1 = "bpcnG4SGRSIpMpUjz2M4P/YhsGTwyDP6dHWSxYM+XHcMa9cn0mOYvw/3A/zB5IEimotGrGSWrce1OBKRZnuJhg==";
    String token2 = "ikQqGCVbNnluED3bzSCPahywJuQ7DoX3eQI/1CXtql5qxPiYNPflNAHvdc7onhd1UJPrHUZQW/1uM6kT3LPKnw==";
    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_login);
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        initPaddingTob();
    }

    @Override
    protected void initData() {

    }


    @OnClick({R.id.btn1, R.id.btn2})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn1:
                connect(token1);
                break;
            case R.id.btn2:
                connect(token2);
                break;
        }
    }
    private void connect(String token) {

        if (getApplicationInfo().packageName.equals(App.getCurProcessName(getApplicationContext()))) {

            RongIMClient.connect(token, new RongIMClient.ConnectCallback() {

                /**
                 * Token 错误。可以从下面两点检查 1.  Token 是否过期，如果过期您需要向 App Server 重新请求一个新的 Token
                 *                  2.  token 对应的 appKey 和工程里设置的 appKey 是否一致
                 */
                @Override
                public void onTokenIncorrect() {
                }

                /**
                 * 连接融云成功
                 * @param userid 当前 token 对应的用户 id
                 */
                @Override
                public void onSuccess(String userid) {
                    Toast.makeText(LoginActivity.this, "连接成功，你的id：" + userid, Toast.LENGTH_SHORT).show();
                    startActivity(MainActivity.class);
                    finish();
                }

                /**
                 * 连接融云失败
                 * @param errorCode 错误码，可到官网 查看错误码对应的注释
                 */
                @Override
                public void onError(RongIMClient.ErrorCode errorCode) {
                }
            });
        }
    }
}
